<?php
/**
 * Created by PhpStorm.
 * User: ysongyang
 * Date: 2016/6/14
 * Time: 14:42
 */
namespace Admin\Controller;

class MessageController extends CommonController{

    public function index(){
        $count = M('message')->count();
        $page = new \Think\Page($count, 10); // 实例化分页类 条数，分页数
        $limit = $page->firstRow . ',' . $page->listRows;
        $this->msg = M('message')->limit($limit)->select();
        $this->page = $page->show();
        $this->display();
    }


    public function replay()
    {
        if(IS_POST){
            $id=$_POST['msgid'];
            $msg_replay = $_POST['msg_replay'];
            $res = M('message')->where(array('id'=>$id))->save(array('msg_replay'=>$msg_replay,'msg_retime'=>time()));

            if($res){
                $data =[
                    'status'=>1,
                    'info'=>'回复留言成功！',
                ];
            }else{
                $data = [
                    'status'=>0,
                    'info'=>'回复留言失败，请稍后再试！',
                ];
            }
            $this->ajaxReturn($data);
        }
    }


    //删除文章
    public function delete($id){
        $res = M('message')->where(array('id'=>$id))->delete();
        if($res){
            $data =[
                'status'=>1,
                'info'=>'删除留言成功！',
            ];
        }else{
            $data = [
                'status'=>0,
                'info'=>'删除留言失败，请稍后再试！',
            ];
        }
        $this->ajaxReturn($data);
    }


    //批量删除文章
    public function deleteAll(){
        if(IS_POST){
            $msgid = $_POST['msgid'];
            $res = M('message')->where(array('id'=>array('in',$msgid)))->delete();
            if($res){
                $data =[
                    'status'=>1,
                    'info'=>'批量删除留言成功！',
                ];
            }else{
                $data = [
                    'status'=>0,
                    'info'=>'批量删除留言失败，请稍后再试！',
                ];
            }
            $this->ajaxReturn($data);
        }
    }
}